<?php
class helper_pomo extends lib_milkphp_helper{

    
	static function _do($domain='default',$fileName=NULL){
		$domain = empty($domain)?'default':$domain;
		static $instance = array();
		if(is_null($instance[$domain]))
			$instance[$domain] = new helper_pomo($fileName);
		return $instance[$domain];
	}
    /**
     * 构造函数
     *
     * @access public
     * @param string $fileName 语言文件名
     * @return void
     */
    public function __construct($fileName=NULL){
    	if(is_file($fileName))
        	$this->addFile($fileName);
    }

    /**
     * 增加一个语言文件
     *
     * @access public
     * @param string $fileName 语言文件名
     * @return void
     */
    public function addFile($fileName){
        $this->_handles[] = $this->GetText($fileName, true);
    }

    public function translate($string){
    	if(is_array($this->_handles))
        foreach ($this->_handles as $handle) {
            $string = $handle->translate($string, $count);
            if (-1 != $count) {
                break;
            }
        }
        return $string;
    }

    public function ngettext($single, $plural, $number){
    	if(is_array($this->_handles))
        foreach ($this->_handles as $handle) {
            $string = $handle->ngettext($single, $plural, $number, $count);
            if (-1 != $count) {
                break;
            }
        }
        return $string;
    }

    public function __destruct(){
    	if(is_array($this->_handles))
        foreach ($this->_handles as $handle) {
            unset($handle);
        }
    }
}
